# -*- coding:utf-8 -*-
'''

@File : WebApiTestTool.py

@Author: 爸爸

@Date : 2019/5/14

@Desc :进行webapi测试工具
'''
import threading
import base64
import json

import requests
import time


def post(url, data):
    if not url.strip():
        return
    r = requests.post(url, data)
    if r.ok:
        return r.content
    return r.status_code
    pass


def get(url):
    if not url.strip():
        return
    r = requests.get(url)
    if r.ok:
        return r.content
    return ""
    pass


def base64encode(s):
    return base64.b64encode(s.encode('utf-8'))


if __name__ == '__main__':
    # ticket="MTcwM0Y5QTktNzg3Ny00QjQxLTk5QTEtODJGNEVFNzcwOTNGLOS5jOmcjeeUqOaItyzkuYzpnI3mtbflhbM="
    # baseurl="http://120.76.188.219:18000/"
    # baseurl="http://localhost:60965/"
    baseurl = "http://10.11.5.31:8200/"
    ticket = "1703F9A9-7877-4B41-99A1-82F4EE77093F"
    pres = post(baseurl + "api/detectionrecords?deviceType=RM2000", {"json": "wersdfsefsdfs"})
    # gres=get(f"{baseurl}api/pda/hello?ticket={ticket}")
    # gres=get(baseurl+"api/pda/IdentificationLocationApi/get?ticket="+ticket)
    gstart = time.time()
    # gres=get(baseurl+"api/pda/reinspectionapi/get?ticket="+ticket+"&inspectionId=34230124-9dc3-4503-838d-8a2730923a5c")
    gres = get("")
    gend = time.time()
    print(gend - gstart)
    print(pres)
    print(gres)

